import axios from '@/utils/request'
const SALARY_TYPE = {
  'salary': '手动发放',
  'salary-settle': '日薪结算',
  'salary-settle-leader': '日薪结算至队长',
  'salary-settle-borker': '日薪结算至经纪人'
}

export default {
  OfficerSalary: {
    entity: { name: 'Transaction', prefix: `officer` },
    list: {
      export: {
        query: {
          '@display': `{
                    'to' : 'entity.getTo().getUsername()',
                    'amount' : 'entity.getAmount()',
                    'type' : '{"salary": "手动发放","salary-settle": "日薪结算","salary-settle-leader": "日薪结算至队长","salary-settle-borker": "日薪结算至经纪人"}[entity.getType()]',
                    'status' : 'entity.getStatus()',
                    'comment': 'entity.getComment()',
                    'createdTime' : 'entity.getCreatedTime().format("Y-m-d H:i:s")'
                }`,
          '@order': 'entity.id|DESC',
          'limit': 100000000
        },
        label: {
          'to': '账号',
          'amount': '金额',
          'type': '类型',
          'status': '状态',
          'comment': '备注',
          'createdTime': '创建时间'
        }
      },
      disabled_actions: ['edit', 'lines', 'delete'],
      list_display: [
        {
          property: 'to.__metadata.staffs',
          label: '员工',
          component: {
            props: ['data'],
            data() {
              return {
                staff: ''
              }
            },
            created() {
              axios.get(`/api/user`, { params: {
                '@expands': `['entity.officer']`
              }}).then(res => {
                if (res.data.officer) {
                  const staff = this.data.find(v => v.__metadata.store.id === res.data.officer.__metadata.store.id)
                  if (staff) {
                    this.staff = staff.__toString
                  }
                }
              })
            },
            render(h) {
              return (
                <span>{this.staff}</span>
              )
            }
          }
        },
        { property: 'to', label: '账号' },
        'amount',
        {
          property: 'type',
          label: '类型',
          component: {
            props: ['data'],
            data() {
              return {
                status: SALARY_TYPE
              }
            },
            render(h) {
              return <span>{this.status[this.data]}</span>
            }
          }
        },
        'status',
        'comment',
        'createdTime'
      ]
    },
    form: {
      fields: [
      ]
    }
  }
}

